package com.fly.container.service;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Scope;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Mr.Fu
 * @date 2022/8/27 下午2:22
 */
@Scope(scopeName = "prototype")
public class SearchService implements InitializingBean, DisposableBean {

    private static final Map<String, String> AREAS = new HashMap<>(4);

    public String search(String keyword) {
        String result = "your input word is : " + keyword;
        System.out.println(result);
        System.out.println(AREAS.get("1"));
        return result;
    }

    public String findCityName(String cityId) {
        String cityName = AREAS.get(cityId);
        if (StringUtils.hasLength(cityName)) {
            return cityName;
        }
        return "不存在该地区";
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("SearchService destroy...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("SearchService init values...");
        AREAS.put("1", "北京");
        System.out.println("SearchService init values areas: " + AREAS);
    }
}
